Update agents_controller.rb

When user stay agent details page, user can use action.

But user use "Delete agent" action, then exception error is occurred.

When action of "Delete agent" run, destory is called, it call "redirect_back".

Although @agent is destroyed, redirect_back used "path = agent_path(@agent)" .

So I add for this case.

if message include "deleted", redirect_back is called by destroy.

then redirect_back use "path = agents_path".

KimJungHun 10 years ago
parent
commit
073b80a5cc
1 changed files with 3 additions and 1 deletions
  1. 3 1
      app/controllers/agents_controller.rb

+ 3 - 1
app/controllers/agents_controller.rb

@@ -179,7 +179,9 @@ class AgentsController < ApplicationController
179 179
 
180 180
   # Sanitize params[:return] to prevent open redirect attacks, a common security issue.
181 181
   def redirect_back(message)
182
-    if params[:return] == "show" && @agent
182
+    if params[:return] == "show" && message.include?("deleted")
183
+      path = agents_path
184
+    elsif params[:return] == "show" && @agent
183 185
       path = agent_path(@agent)
184 186
     elsif params[:return] =~ /\A#{Regexp::escape scenarios_path}\/\d+\Z/
185 187
       path = params[:return]